/****************************************************************************\
*                                                                            *
*  Copyright 2008 The CAnt2 Project (http://code.google.com/p/cant2)         *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
\****************************************************************************/

#ifndef INCLUDED_FASTBOOLEAN_H__
#define INCLUDED_FASTBOOLEAN_H__

#include "FastBooleanType.h"

namespace FastBoolean {

    // This file may be compiler specific.
    
    // These functions serve two needs.  The first is to make generating 
    // bool_t values a little easier/standard.  The second is to be 
    // branchless, assuming that the target machine supports branchless 
    // instructions.
    
    // Note that these functions are used by performance critical code.

    bool_t Less   ( const int lhs, const int rhs )
    {
        return ( lhs < rhs ) ? True : False;
    }

    bool_t LessEq ( const int lhs, const int rhs )
    {
        return ( lhs <= rhs ) ? True : False;
    }

    bool_t Equals ( const int lhs, const int rhs )
    {
        return ( lhs == rhs ) ? True : False;
    }

    // This functor is intended to make range tests more readable than the simple
    // function would be
    //      InRangeInclusive(a,b,c);    // Which is the range, which the value being tested?
    //      InRangeInclusive(a,b)(c);   // Better. a,b look like the range, and c the value.
    struct InRangeInclusive
    {
        InRangeInclusive ( const int min, const int max ) : min ( min ), max ( max ) {}
        bool_t operator() ( const int v ) const
        {
            return LessEq ( min, v ) & LessEq ( v, max );
        }

    private:
        InRangeInclusive& operator= ( const InRangeInclusive& );

    private:
        const int min, max;
    };

}

#endif /* #ifndef INCLUDED_FASTBOOLEAN_H__ */

